#!/bin/bash

################################
# Fan curves for X86 handhelds #
################################

case "$1" in
    start)
        model_output=$(batocera-model)
        # ayn loki zero
        if [[ $model_output == "Loki_Zero" ]]; then
            # fan speeds [0-255]
            echo 60 > /sys/class/hwmon/hwmon5/pwm1_auto_point1_pwm
            echo 100 > /sys/class/hwmon/hwmon5/pwm1_auto_point2_pwm
            echo 130 > /sys/class/hwmon/hwmon5/pwm1_auto_point3_pwm
            echo 170 > /sys/class/hwmon/hwmon5/pwm1_auto_point4_pwm
            echo 210 > /sys/class/hwmon/hwmon5/pwm1_auto_point5_pwm
            # temps [0-100]
            echo 40 > /sys/class/hwmon/hwmon5/pwm1_auto_point1_temp 
            echo 55 > /sys/class/hwmon/hwmon5/pwm1_auto_point2_temp
            echo 66 > /sys/class/hwmon/hwmon5/pwm1_auto_point3_temp
            echo 77 > /sys/class/hwmon/hwmon5/pwm1_auto_point4_temp
            echo 86 > /sys/class/hwmon/hwmon5/pwm1_auto_point5_temp
            # user controlled mode
            echo 2 > /sys/class/hwmon/hwmon5/pwm1_enable
        fi
        ;;
    stop)
        # bios controlled mode
        if [[ $model_output == "Loki_Zero" ]]; then
            echo 0 > /sys/class/hwmon/hwmon5/pwm1_enable
        fi
        ;;
    restart)
		stop
		start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac

exit 0
